package com.zsy.petshop_01.service.impl;

import com.zsy.petshop_01.common.result.ResponseResult;
import com.zsy.petshop_01.manager.SubscribeManager;
import com.zsy.petshop_01.model.dto.ShowSubscribeUserDto;
import com.zsy.petshop_01.model.entity.SubscribeNum;
import com.zsy.petshop_01.model.vo.subscribe.AnswerVo;
import com.zsy.petshop_01.model.vo.subscribe.SubscribeVo;
import com.zsy.petshop_01.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;

@Service
public class SubscribeServiceImpl implements SubscribeService {
    @Autowired
    SubscribeManager subscribeManager;

    @Override
    public ResponseResult<?> subscribe(SubscribeVo subscribeVo, HttpServletRequest request) {
        Integer userId = Integer.parseInt(request.getHeader("user_id"));
        String time = subscribeVo.getTime();
        Boolean isMorning = subscribeVo.getIsMorning();
        String message = subscribeVo.getMessage();
        subscribeManager.subscribe(time, message, isMorning, userId);
        return ResponseResult.success("预约成功");
    }

    @Override
    public ResponseResult<?> selectSubscribeInDay(String time) {
        SubscribeNum subscribeNum = subscribeManager.selectSubscribeInDay(time);
        return ResponseResult.success(subscribeNum);
    }

    @Override
    public ResponseResult<?> selectSubscribeByUserId(HttpServletRequest request) {
        Integer userId = Integer.parseInt(request.getHeader("user_id"));
        List<ShowSubscribeUserDto> showSubscribeUserDtos = subscribeManager.selectSubscribeByUserId(userId);
        return ResponseResult.success(showSubscribeUserDtos);
    }

    @Override
    public ResponseResult<?> selectSubscribeByMorning(Integer id, Boolean isMorning) {
        List<ShowSubscribeUserDto> showSubscribeUserDtos = subscribeManager.selectSubscribeByMorning(id, isMorning);
        return ResponseResult.success(showSubscribeUserDtos);
    }

    @Override
    public ResponseResult<?> ownerAnswer(AnswerVo answerVo) {
        subscribeManager.ownerAnswer(answerVo);
        return ResponseResult.success();
    }
}
